<?php

namespace App\Miya\Tools;

use Illuminate\Support\Str;
use Overtrue\Pinyin\Pinyin;

class TagTool
{
    static public function makeTag($str, $random = false)
    {
        $pinyin = new Pinyin();
        switch (config('setting.tag_type')) {
            case 1:
                $tag = $pinyin->permalink($str);
                break;
            case 2:
                $tag = $pinyin->abbr($str);
                break;
        }
        if ($random) {
            $tag = sprintf('%s-%s', $tag, strtolower(Str::random(4)));
        }
        return $tag;
    }
}
